package com.evan.designpatterns.factory.homework3.simplefactory;

/**
 * @author :liujiapeng01
 * @date :2019-03-07 10:06
 **/
public class SimpleFactory {


    public static Book getBookByClass(Class<? extends Book> clazz) {
        try {
            Object o = clazz.newInstance();
            return (Book) o;
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        throw new IllegalArgumentException("cannot find the class" + clazz.getName());
    }


    public static Book getBookByNickName(String name) {
        switch (name) {
            case "effective":
                return new EffectiveJava();
            case "thinking":
                return new ThinkingInJava();
            default:
                throw new IllegalArgumentException("cannot find the nickName" + name);
        }
    }


}
